﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using Jacaranda.Data;

namespace Jacaranda.Model
{
    public class Constant : ParameterGenerationNode
    {
        public Constant(object value)
        {
            Value = value;
        }

        public object Value { get; set; }

        private int sequence;

        internal override string GenerateSql(Type propertyEntityType)
        {
            string parameterName = "conditionParameter" + ParameterIndex + "_" + sequence++;

            DbParameter parameter = DataAccess.Create().CreateDbParameter();

            parameter.ParameterName = parameterName;
            parameter.Value = Value;

            Command.Parameters.Add(parameter);

            return DataAccess.Create().CreateParameterizedExpression(parameterName);
        }
    }
}
